HTMLify
Search Insert Position.cpp
Views: 1 | Author: cody
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | int searchInsert(vector<int>& arr, int m) { // Write your code here. int n = arr.size(); int start = 0; int end = n-1; int mid = start +(end - start) /2; int ans = n; while(start<=end){ if(arr[mid]>= m){ ans = mid; end = mid - 1; } else{ start = mid + 1; } mid = start + (end - start) /2; } return ans; } |